package com.zhi.service;

import com.zhi.dao.UserDao;
import com.zhi.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author WenZhi Luo
 * @version 1.0
 * @date 2020/2/2 21:40
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    public User getUser(int id){
        return userDao.getUserById(id);
    }

    public User getById(int id) {
        return userDao.getUserById(id);
    }

    @Transactional
    public boolean tx() {
        User u1= new User();
        u1.setId(2);
        u1.setName("2222");
        userDao.insert(u1);

        User u2= new User();
        u2.setId(1);
        u2.setName("11111");
        userDao.insert(u2);

        return true;
    }
}
